class Solution(object):
    def lengthOfLongestSubstring(self, s):
        """
        :type s: str
        :rtype: int
        """
        l = 0
        r = 0
        max_len = 0
        sub_s = ""
        for r in range(len(s)):
            if s[r] not in sub_s:
                sub_s += s[r]
                max_len = max(max_len, r - l + 1)
            else:
                l = sub_s.index(s[r]) + 1 + l
                sub_s = s[l:r+1]         
        return max_len
